package com.lkm.market2_0.m_imple.steelyardserver.server.sendtask;

import com.lkm.frame.P;
import com.lkm.frame.task2.ITaskExecutor;
import com.lkm.frame.task2.TaskManager;
import com.lkm.hardware_connect.IHardwareControler;
import com.lkm.javatool.CollectionHelp;
import com.lkm.market2_0.help.UIP;
import com.lkm.market2_0.m_imple.steelyardserver.server.AbsSendWriteTask;
import com.lkm.market2_0.m_imple.steelyardserver.server.ReceiveTask;



public class SendTitleWriteTask extends AbsSendWriteTask {
    public SendTitleWriteTask(ITaskExecutor<Object[], Void, Boolean> taskExecutor, TaskManager mTaskManager, IHardwareControler bluetoothSocket, ReceiveTask mReceiveTask,String title, String subTitle) {
        super(taskExecutor, SendTitleWriteTask.class.getName(), mTaskManager, bluetoothSocket, mReceiveTask);

        setParam(new Object[]{title,subTitle});
    }


    





    @Override
    protected byte onGetRequestCMD(int[] outDataSize) {
        outDataSize[0]=64;
        return 0x05;
    }

    @Override
    protected byte[] onGetSendDataItem(int index) {
        if(index>0)return null;

        byte[] data =null;
        String title=(String)getParam()[0];
        title=holdCharWidth32(title);

        String subTitle=(String)getParam()[1];
        subTitle=holdCharWidth32(subTitle);

        try {
            data=title.getBytes("gbk");;
            data=CollectionHelp.concatByte(data,subTitle.getBytes("gbk"));

        } catch (Exception e) {
            data=null;
        }

        return data;
    }


    @Override
    public void onPreExecute() {
        super.onPreExecute();

        if(P.isDebug()) {
            P.p("=======开始设置标题");
            if(UIP.isPrint()){
                UIP.p("Send设置标题：开始",mReceiveTask==null?"":mReceiveTask.steelyardMac);
            }
        }
    }
    @Override
    public void onCancel() {
        super.onCancel();

        if(P.isDebug()) {
            P.p("=======设置标题 取消了");
            if(UIP.isPrint()){
                UIP.p("Send设置标题：取消",mReceiveTask==null?"":mReceiveTask.steelyardMac);
            }
        }
    }
    @Override
    public void onFinish(Boolean aBoolean) {
        super.onFinish(aBoolean);

        if(P.isDebug()) {
            P.p("======设置标题是否成功："+aBoolean);
            if(UIP.isPrint()){
                UIP.p("Send设置标题：成功？"+aBoolean,mReceiveTask==null?"":mReceiveTask.steelyardMac);
            }
        }
    }
}